package com.jerry.huihome.module.find_near_mine.activity;

import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.jerry.huihome.R;
import com.jerry.huihome.base.BaseActivity;
import com.jerry.huihome.module.find_near_mine.adapter.ImageAdapter;
import com.jerry.huihome.module.find_near_mine.entity.AfflatusItemEntity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class ImageActivity extends BaseActivity{
    @BindView(R.id.item_list_image)
    ViewPager imagetobig;
    @BindView(R.id.imgcount)
    TextView imgcount;
    private List<AfflatusItemEntity.BodyBean.DetailItemsBean> detailItemsBean;
    private ArrayList<String> url;

    @Override
    protected void initViews(){
       /* Intent intent = getIntent();
        String imageUrl = intent.getStringExtra("imageUrl");
        ImageLoader.getInstance().loadImage(imageUrl, BaseApplication.getApplication().getImageOptions(), new SimpleImageLoadingListener(){
            @Override
            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage){
                super.onLoadingComplete(imageUri, view, loadedImage);
                imagetobig.setImageBitmap(loadedImage);
            }
        });*/
        Intent intent = getIntent();
        url = intent.getStringArrayListExtra("url");
        int position = intent.getIntExtra("position", -1);
        ImageAdapter imageAdapter = new ImageAdapter(this, url,position);
        imagetobig.setAdapter(imageAdapter);
        imagetobig.setCurrentItem(position);
        imgcount.setText(position+1+"/"+ url.size());
        imagetobig.addOnPageChangeListener(new ViewPager.OnPageChangeListener(){
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels){
            }

            @Override
            public void onPageSelected(int position){
                imgcount.setText(position+1+"/"+ url.size());
            }

            @Override
            public void onPageScrollStateChanged(int state){
            }
        });


    }
   /* private List<Bitmap> bitmapList = new ArrayList<>();
    @Subscribe(threadMode = ThreadMode.MainThread)
    public void loadListImg(EventMessage eventMessage){
        detailItemsBean = eventMessage.getDetailItemsBean();
        int size = detailItemsBean.size();
        for(int i = 1 ; i<=size;i++){
            String listImgUrl = detailItemsBean.get(i).getListImg();
            ImageLoader.getInstance().loadImage(listImgUrl, BaseApplication.getApplication().getImageOptions(), new SimpleImageLoadingListener(){
                @Override
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage){
                    super.onLoadingComplete(imageUri, view, loadedImage);
                    //imagetobig.setImageBitmap(loadedImage);
                    bitmapList.add(loadedImage);
                }
            });
        }
    }*/

    @Override
    protected int getLayoutId(){
        return R.layout.activity_image;
    }

    @OnClick(R.id.gobackfromimage)
    public void gobackfromimage(View view){
        finish();
    }
}
